using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Security;
using System.Web.UI;
using System.Windows.Forms;

using PickGold.Charting.Borders3D;
using PickGold.Charting.Design;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	internal class ChartPicture : ChartElement, IServiceProvider
	{
		private AnnotationCollection _annotations;
		private AntiAliasingStyles _antiAliasing = AntiAliasingStyles.All;
		private Color _backColor = Color.White;
		private GradientStyle _backGradientStyle;
		private ChartHatchStyle _backHatchStyle;
		private string _backImage = "";
		private ChartImageAlignmentStyle _backImageAlign;
		private Color _backImageTransparentColor = Color.Empty;
		private ChartImageWrapMode _backImageWrapMode;
		private Color _backSecondaryColor = Color.Empty;
		private Color _borderColor = Color.White;
		private ChartDashStyle _borderDashStyle;
		private BorderSkin _borderSkin;
		private int _borderWidth = 1;
		private ChartAreaCollection _chartAreas;
		private RectangleF _chartBorderPosition = RectangleF.Empty;
		private DataManipulator _dataManipulator = new DataManipulator();
		private FontCache _fontCache = new FontCache();
		private int _height = 300;
		private bool _isMapEnabled = true;
		private bool _isSoftShadows = true;
		private LegendCollection _legends;
		private MapAreasCollection _mapAreas;
		private bool _suppressExceptions;
		private TextAntiAliasingQuality _textAntiAliasingQuality = TextAntiAliasingQuality.High;
		private RectangleF _titlePosition = RectangleF.Empty;
		private TitleCollection _titles;
		private int _width = 300;
		internal AnnotationSmartLabel annotationSmartLabel = new AnnotationSmartLabel();
		internal const float elementSpacing = 3f;
		internal HotRegionsList hotRegionsList;
		internal bool isPrinting;
		internal bool isSelectionMode;
		internal const float maxTitleSize = 15f;
		private System.Windows.Forms.RightToLeft rightToLeft;

		internal event EventHandler<ChartPaintEventArgs> AfterPaint;

		internal event EventHandler<ChartPaintEventArgs> BeforePaint;

		public ChartPicture(IServiceContainer container)
		{
			if (container == null)
			{
				throw new ArgumentNullException(SR.ExceptionInvalidServiceContainer);
			}
			base.Common = new CommonElements(container);
			this.ChartGraph = new ChartGraphics(base.Common);
			this.hotRegionsList = new HotRegionsList(base.Common);
			this._borderSkin = new BorderSkin(this);
			this._chartAreas = new ChartAreaCollection(this);
			this._legends = new LegendCollection(this);
			this._titles = new TitleCollection(this);
			this._annotations = new AnnotationCollection(this);
			this._dataManipulator.Common = base.Common;
			this._mapAreas = new MapAreasCollection();
		}

		internal void AlignChartAreas(AreaAlignmentStyles type)
		{
			if (this.IsAreasAlignmentRequired())
			{
				foreach (ChartArea area in this.ChartAreas)
				{
					if (area.Visible)
					{
						ArrayList areasGroup = this.GetAlignedAreasGroup(area, type, AreaAlignmentOrientations.Vertical);
						if (areasGroup.Count > 0)
						{
							this.AlignChartAreasPlotPosition(areasGroup, AreaAlignmentOrientations.Vertical);
						}
						areasGroup = this.GetAlignedAreasGroup(area, type, AreaAlignmentOrientations.Horizontal);
						if (areasGroup.Count > 0)
						{
							this.AlignChartAreasPlotPosition(areasGroup, AreaAlignmentOrientations.Horizontal);
						}
					}
				}
			}
		}

		internal void AlignChartAreasAxesView(ChartArea changedArea, AreaAlignmentOrientations orientation)
		{
			if (this.IsAreasAlignmentRequired())
			{
				foreach (ChartArea area in this.ChartAreas)
				{
					if (area.Visible)
					{
						ArrayList list = this.GetAlignedAreasGroup(area, AreaAlignmentStyles.AxesView, orientation);
						if (list.Contains(changedArea))
						{
							foreach (ChartArea area2 in list)
							{
								area2.alignmentInProcess = true;
								if (orientation == AreaAlignmentOrientations.Vertical)
								{
									area2.AxisX.ScaleView.Position = changedArea.AxisX.ScaleView.Position;
									area2.AxisX.ScaleView.Size = changedArea.AxisX.ScaleView.Size;
									area2.AxisX.ScaleView.SizeType = changedArea.AxisX.ScaleView.SizeType;
									area2.AxisX2.ScaleView.Position = changedArea.AxisX2.ScaleView.Position;
									area2.AxisX2.ScaleView.Size = changedArea.AxisX2.ScaleView.Size;
									area2.AxisX2.ScaleView.SizeType = changedArea.AxisX2.ScaleView.SizeType;
								}
								if (orientation == AreaAlignmentOrientations.Horizontal)
								{
									area2.AxisY.ScaleView.Position = changedArea.AxisY.ScaleView.Position;
									area2.AxisY.ScaleView.Size = changedArea.AxisY.ScaleView.Size;
									area2.AxisY.ScaleView.SizeType = changedArea.AxisY.ScaleView.SizeType;
									area2.AxisY2.ScaleView.Position = changedArea.AxisY2.ScaleView.Position;
									area2.AxisY2.ScaleView.Size = changedArea.AxisY2.ScaleView.Size;
									area2.AxisY2.ScaleView.SizeType = changedArea.AxisY2.ScaleView.SizeType;
								}
								area2.alignmentInProcess = false;
							}
							continue;
						}
					}
				}
			}
		}

		private void AlignChartAreasPlotPosition(ArrayList areasGroup, AreaAlignmentOrientations orientation)
		{
			RectangleF ef = ((ChartArea)areasGroup[0]).PlotAreaPosition.ToRectangleF();
			foreach (ChartArea area in areasGroup)
			{
				if (area.PlotAreaPosition.X > ef.X)
				{
					ef.X += area.PlotAreaPosition.X - ef.X;
					ef.Width -= area.PlotAreaPosition.X - ef.X;
				}
				if (area.PlotAreaPosition.Y > ef.Y)
				{
					ef.Y += area.PlotAreaPosition.Y - ef.Y;
					ef.Height -= area.PlotAreaPosition.Y - ef.Y;
				}
				if (area.PlotAreaPosition.Right < ef.Right)
				{
					ef.Width -= ef.Right - area.PlotAreaPosition.Right;
					if (ef.Width < 5f)
					{
						ef.Width = 5f;
					}
				}
				if (area.PlotAreaPosition.Bottom < ef.Bottom)
				{
					ef.Height -= ef.Bottom - area.PlotAreaPosition.Bottom;
					if (ef.Height < 5f)
					{
						ef.Height = 5f;
					}
				}
			}
			foreach (ChartArea area2 in areasGroup)
			{
				RectangleF ef2 = area2.PlotAreaPosition.ToRectangleF();
				if ((orientation & AreaAlignmentOrientations.Vertical) == AreaAlignmentOrientations.Vertical)
				{
					ef2.X = ef.X;
					ef2.Width = ef.Width;
				}
				if ((orientation & AreaAlignmentOrientations.Horizontal) == AreaAlignmentOrientations.Horizontal)
				{
					ef2.Y = ef.Y;
					ef2.Height = ef.Height;
				}
				area2.PlotAreaPosition.SetPositionNoAuto(ef2.X, ef2.Y, ef2.Width, ef2.Height);
				ef2.X = ((ef2.X - area2.Position.X) / area2.Position.Width) * 100f;
				ef2.Y = ((ef2.Y - area2.Position.Y) / area2.Position.Height) * 100f;
				ef2.Width = (ef2.Width / area2.Position.Width) * 100f;
				ef2.Height = (ef2.Height / area2.Position.Height) * 100f;
				area2.InnerPlotPosition.SetPositionNoAuto(ef2.X, ef2.Y, ef2.Width, ef2.Height);
				if ((orientation & AreaAlignmentOrientations.Vertical) == AreaAlignmentOrientations.Vertical)
				{
					area2.AxisX2.AdjustLabelFontAtSecondPass(this.ChartGraph, area2.InnerPlotPosition.Auto);
					area2.AxisX.AdjustLabelFontAtSecondPass(this.ChartGraph, area2.InnerPlotPosition.Auto);
				}
				if ((orientation & AreaAlignmentOrientations.Horizontal) == AreaAlignmentOrientations.Horizontal)
				{
					area2.AxisY2.AdjustLabelFontAtSecondPass(this.ChartGraph, area2.InnerPlotPosition.Auto);
					area2.AxisY.AdjustLabelFontAtSecondPass(this.ChartGraph, area2.InnerPlotPosition.Auto);
				}
			}
		}

		private void AlignChartAreasPosition()
		{
			if (this.IsAreasAlignmentRequired())
			{
				foreach (ChartArea area in this.ChartAreas)
				{
					if ((area.Visible && (area.AlignWithChartArea != "NotSet")) && ((area.AlignmentStyle & AreaAlignmentStyles.Position) == AreaAlignmentStyles.Position))
					{
						RectangleF ef = area.Position.ToRectangleF();
						ChartArea area2 = this.ChartAreas[area.AlignWithChartArea];
						if ((area.AlignmentOrientation & AreaAlignmentOrientations.Vertical) == AreaAlignmentOrientations.Vertical)
						{
							ef.X = area2.Position.X;
							ef.Width = area2.Position.Width;
						}
						if ((area.AlignmentOrientation & AreaAlignmentOrientations.Horizontal) == AreaAlignmentOrientations.Horizontal)
						{
							ef.Y = area2.Position.Y;
							ef.Height = area2.Position.Height;
						}
						area.Position.SetPositionNoAuto(ef.X, ef.Y, ef.Width, ef.Height);
					}
				}
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (this.ChartGraph != null)
				{
					this.ChartGraph.Dispose();
					this.ChartGraph = null;
				}
				if (this._legends != null)
				{
					this._legends.Dispose();
					this._legends = null;
				}
				if (this._titles != null)
				{
					this._titles.Dispose();
					this._titles = null;
				}
				if (this._chartAreas != null)
				{
					this._chartAreas.Dispose();
					this._chartAreas = null;
				}
				if (this._annotations != null)
				{
					this._annotations.Dispose();
					this._annotations = null;
				}
				if (this.hotRegionsList != null)
				{
					this.hotRegionsList.Dispose();
					this.hotRegionsList = null;
				}
				if (this._fontCache != null)
				{
					this._fontCache.Dispose();
					this._fontCache = null;
				}
				if (this._borderSkin != null)
				{
					this._borderSkin.Dispose();
					this._borderSkin = null;
				}
				if (this._mapAreas != null)
				{
					this._mapAreas.Dispose();
					this._mapAreas = null;
				}
			}
			base.Dispose(disposing);
		}

		private ArrayList GetAlignedAreasGroup(ChartArea masterArea, AreaAlignmentStyles type, AreaAlignmentOrientations orientation)
		{
			ArrayList list = new ArrayList();
			foreach (ChartArea area in this.ChartAreas)
			{
				if (((area.Visible && (area.Name != masterArea.Name)) && ((area.AlignWithChartArea == masterArea.Name) && ((area.AlignmentStyle & type) == type))) && ((area.AlignmentOrientation & orientation) == orientation))
				{
					list.Add(area);
				}
			}
			if (list.Count > 0)
			{
				list.Insert(0, masterArea);
			}
			return list;
		}

		internal Title GetDefaultTitle(bool create)
		{
			Title item = null;
			foreach (Title title2 in this.Titles)
			{
				if (title2.Name == "Default Title")
				{
					item = title2;
				}
			}
			if ((item == null) && create)
			{
				item = new Title();
				item.Name = "Default Title";
				this.Titles.Insert(0, item);
			}
			return item;
		}

		internal TextRenderingHint GetTextRenderingHint()
		{
			TextRenderingHint singleBitPerPixelGridFit = TextRenderingHint.SingleBitPerPixelGridFit;
			if ((this.AntiAliasing & AntiAliasingStyles.Text) == AntiAliasingStyles.Text)
			{
				singleBitPerPixelGridFit = TextRenderingHint.ClearTypeGridFit;
				if (this.TextAntiAliasingQuality == TextAntiAliasingQuality.Normal)
				{
					return TextRenderingHint.AntiAlias;
				}
				if (this.TextAntiAliasingQuality == TextAntiAliasingQuality.SystemDefault)
				{
					singleBitPerPixelGridFit = TextRenderingHint.SystemDefault;
				}
				return singleBitPerPixelGridFit;
			}
			return TextRenderingHint.SingleBitPerPixelGridFit;
		}

		private void InspectChartDimensions(int width, int height)
		{
			if (base.Chart.IsDesignMode() && ((width * height) > 0x6400000))
			{
				throw new ArgumentException(SR.ExceptionChartOutOfLimits);
			}
		}

		internal override void Invalidate()
		{
			base.Invalidate();
		}

		private bool IsAreasAlignmentRequired()
		{
			bool flag = false;
			foreach (ChartArea area in this.ChartAreas)
			{
				if (area.Visible && (area.AlignWithChartArea != "NotSet"))
				{
					flag = true;
					if (this._chartAreas.IndexOf(area.AlignWithChartArea) < 0)
					{
						throw new InvalidOperationException(SR.ExceptionChartAreaNameReferenceInvalid(area.Name, area.AlignWithChartArea));
					}
				}
			}
			return flag;
		}

		private bool IsToolTipsEnabled()
		{
			foreach (Series series in base.Common.DataManager.Series)
			{
				if (series.ToolTip.Length > 0)
				{
					return true;
				}
				if ((series.LegendToolTip.Length > 0) || (series.LabelToolTip.Length > 0))
				{
					return true;
				}
				if (!series.IsFastChartType())
				{
					foreach (DataPoint point in series.Points)
					{
						if (point.ToolTip.Length > 0)
						{
							return true;
						}
						if ((point.LegendToolTip.Length > 0) || (point.LabelToolTip.Length > 0))
						{
							return true;
						}
					}
					continue;
				}
			}
			foreach (Legend legend in this.Legends)
			{
				foreach (LegendItem item in legend.CustomItems)
				{
					if (item.ToolTip.Length > 0)
					{
						return true;
					}
				}
			}
			foreach (Title title in this.Titles)
			{
				if (title.ToolTip.Length > 0)
				{
					return true;
				}
			}
			return false;
		}

		public void LoadTemplate(Stream stream)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}
			ChartSerializer service = (ChartSerializer)base.Common.container.GetService(typeof(ChartSerializer));
			if (service != null)
			{
				string serializableContent = service.SerializableContent;
				string nonSerializableContent = service.NonSerializableContent;
				SerializationFormat format = service.Format;
				bool isUnknownAttributeIgnored = service.IsUnknownAttributeIgnored;
				bool isTemplateMode = service.IsTemplateMode;
				service.Content = SerializationContents.Appearance;
				service.Format = SerializationFormat.Xml;
				service.IsUnknownAttributeIgnored = true;
				service.IsTemplateMode = true;
				try
				{
					service.Load(stream);
				}
				catch (Exception exception)
				{
					throw new InvalidOperationException(exception.Message);
				}
				finally
				{
					service.SerializableContent = serializableContent;
					service.NonSerializableContent = nonSerializableContent;
					service.Format = format;
					service.IsUnknownAttributeIgnored = isUnknownAttributeIgnored;
					service.IsTemplateMode = isTemplateMode;
				}
			}
		}

		public void LoadTemplate(string name)
		{
			if (name == null)
			{
				throw new ArgumentNullException("name");
			}
			Stream stream = this.LoadTemplateData(name);
			this.LoadTemplate(stream);
			stream.Close();
		}

		private Stream LoadTemplateData(string url)
		{
			Stream responseStream = null;
			if (((responseStream == null) && (base.Common != null)) && ((base.Common.Chart != null) && (base.Common.Chart.Page != null)))
			{
				try
				{
					responseStream = new FileStream(base.Common.Chart.Page.MapPath(url), FileMode.Open);
				}
				catch (NotSupportedException)
				{
					responseStream = null;
				}
				catch (SecurityException)
				{
					responseStream = null;
				}
				catch (FileNotFoundException)
				{
					responseStream = null;
				}
				catch (DirectoryNotFoundException)
				{
					responseStream = null;
				}
				catch (PathTooLongException)
				{
					responseStream = null;
				}
			}
			if (responseStream == null)
			{
				Uri requestUri = null;
				try
				{
					requestUri = new Uri(url);
				}
				catch (UriFormatException)
				{
					requestUri = null;
				}
				if (((requestUri == null) && (base.Common != null)) && (base.Common.Chart != null))
				{
					string webFormDocumentURL = base.Common.Chart.WebFormDocumentURL;
					int num = webFormDocumentURL.LastIndexOf('/');
					if (num != -1)
					{
						webFormDocumentURL = webFormDocumentURL.Substring(0, num + 1);
					}
					try
					{
						requestUri = new Uri(new Uri(webFormDocumentURL), url);
					}
					catch (UriFormatException)
					{
						requestUri = null;
					}
				}
				if (requestUri != null)
				{
					try
					{
						responseStream = WebRequest.Create(requestUri).GetResponse().GetResponseStream();
					}
					catch (NotSupportedException)
					{
						responseStream = null;
					}
					catch (NotImplementedException)
					{
						responseStream = null;
					}
					catch (SecurityException)
					{
						responseStream = null;
					}
				}
			}
			if (responseStream == null)
			{
				responseStream = new FileStream(url, FileMode.Open);
			}
			return responseStream;
		}

		protected virtual void OnAfterPaint(ChartPaintEventArgs e)
		{
			if (this.AfterPaint != null)
			{
				this.AfterPaint(this, e);
			}
		}

		protected virtual void OnBeforePaint(ChartPaintEventArgs e)
		{
			if (this.BeforePaint != null)
			{
				this.BeforePaint(this, e);
			}
		}

		internal void Paint(Graphics graph, bool paintTopLevelElementOnly)
		{
			this.annotationSmartLabel.Reset();
			if ((this.Width >= 5) && (this.Height >= 5))
			{
				if (this.IsMapEnabled)
				{
					HotRegionsList hotRegionsList = base.Common.HotRegionsList;
					hotRegionsList.ProcessChartMode |= ProcessMode.ImageMaps | ProcessMode.Paint;
					for (int i = 0; i < this.MapAreas.Count; i++)
					{
						MapArea area = this.MapAreas[i];
						if (!area.IsCustom)
						{
							this.MapAreas.RemoveAt(i);
							i--;
						}
					}
				}
				ChartImage image = this as ChartImage;
				if ((((image != null) && !image.boundToDataSource) && ((base.Common != null) && (base.Common.Chart != null))) && !base.Common.Chart.IsDesignMode())
				{
					base.Common.Chart.DataBind();
				}
				this.ChartGraph.Graphics = graph;
				base.Common.graph = this.ChartGraph;
				this.ChartGraph.AntiAliasing = this._antiAliasing;
				this.ChartGraph.softShadows = this._isSoftShadows;
				this.ChartGraph.TextRenderingHint = this.GetTextRenderingHint();
				try
				{
					if (!paintTopLevelElementOnly)
					{
						this.OnBeforePaint(new ChartPaintEventArgs(base.Chart, this.ChartGraph, base.Common, new ElementPosition(0f, 0f, 100f, 100f)));
						bool calcAreaPositionOnly = false;
						foreach (ChartArea area2 in this._chartAreas)
						{
							if (area2.Visible)
							{
								area2.Set3DAnglesAndReverseMode();
								area2.SetTempValues();
								area2.ReCalcInternal();
								if (area2.Area3DStyle.Enable3D && !area2.chartAreaIsCurcular)
								{
									calcAreaPositionOnly = true;
								}
							}
						}
						base.Common.Chart.CallOnCustomize();
						this.Resize(this.ChartGraph, calcAreaPositionOnly);
						bool flag2 = false;
						foreach (ChartArea area3 in this._chartAreas)
						{
							if ((area3.Area3DStyle.Enable3D && !area3.chartAreaIsCurcular) && area3.Visible)
							{
								flag2 = true;
								area3.Estimate3DInterval(this.ChartGraph);
								area3.ReCalcInternal();
							}
						}
						if (calcAreaPositionOnly)
						{
							if (flag2)
							{
								base.Common.Chart.CallOnCustomize();
							}
							this.Resize(this.ChartGraph);
						}
						if (((this._borderSkin.SkinStyle != BorderSkinStyle.None) && (this.Width > 20)) && (this.Height > 20))
						{
							this.ChartGraph.FillRectangleAbs(new RectangleF(0f, 0f, (float)(this.Width - 1), (float)(this.Height - 1)), this._borderSkin.PageColor, ChartHatchStyle.None, "", ChartImageWrapMode.Tile, Color.Empty, ChartImageAlignmentStyle.Center, GradientStyle.None, Color.Empty, this._borderSkin.PageColor, 1, ChartDashStyle.Solid, PenAlignment.Inset);
							this.ChartGraph.Draw3DBorderAbs(this._borderSkin, this._chartBorderPosition, this.BackColor, this.BackHatchStyle, this.BackImage, this.BackImageWrapMode, this.BackImageTransparentColor, this.BackImageAlignment, this.BackGradientStyle, this.BackSecondaryColor, this.BorderColor, this.BorderWidth, this.BorderDashStyle);
						}
						else
						{
							this.ChartGraph.FillRectangleAbs(new RectangleF(0f, 0f, (float)(this.Width - 1), (float)(this.Height - 1)), this.BackColor, this.BackHatchStyle, this.BackImage, this.BackImageWrapMode, this.BackImageTransparentColor, this.BackImageAlignment, this.BackGradientStyle, this.BackSecondaryColor, this.BorderColor, this.BorderWidth, this.BorderDashStyle, PenAlignment.Inset);
						}
						base.Chart.CallOnPrePaint(new ChartPaintEventArgs(base.Chart, this.ChartGraph, base.Common, new ElementPosition(0f, 0f, 100f, 100f)));
						foreach (ChartArea area4 in this._chartAreas)
						{
							if (area4.Visible)
							{
								area4.Paint(this.ChartGraph);
							}
						}
						foreach (ChartArea area5 in this._chartAreas)
						{
							area5.intervalData = double.NaN;
						}
						foreach (Legend legend in this.Legends)
						{
							legend.Paint(this.ChartGraph);
						}
						foreach (Title title in this.Titles)
						{
							title.Paint(this.ChartGraph);
						}
						base.Chart.CallOnPostPaint(new ChartPaintEventArgs(base.Chart, this.ChartGraph, base.Common, new ElementPosition(0f, 0f, 100f, 100f)));
					}
					this.Annotations.Paint(this.ChartGraph, paintTopLevelElementOnly);
					if (!this.isSelectionMode)
					{
						foreach (ChartArea area6 in this._chartAreas)
						{
							if (area6.Visible)
							{
								area6.PaintCursors(this.ChartGraph, paintTopLevelElementOnly);
							}
						}
					}
					foreach (ChartArea area7 in this._chartAreas)
					{
						if (area7.Visible)
						{
							area7.Restore3DAnglesAndReverseMode();
							area7.GetTempValues();
						}
					}
				}
				catch (Exception)
				{
					throw;
				}
				finally
				{
					this.OnAfterPaint(new ChartPaintEventArgs(base.Chart, this.ChartGraph, base.Common, new ElementPosition(0f, 0f, 100f, 100f)));
					foreach (ChartArea area8 in this._chartAreas)
					{
						if (area8.Visible)
						{
							area8.Restore3DAnglesAndReverseMode();
							area8.GetTempValues();
						}
					}
					if (base.Chart.IsDesignMode())
					{
						base.Chart.MapAreas.RemoveNonCustom();
					}
				}
			}
		}

		internal void PaintOffScreen()
		{
			if ((this.Width > 0) && (this.Height > 0))
			{
				HotRegionsList hotRegionsList = base.Common.HotRegionsList;
				hotRegionsList.ProcessChartMode |= ProcessMode.HotRegions;
				this.isSelectionMode = true;
				base.Common.HotRegionsList.Clear();
				Bitmap image = new Bitmap(this.Width, this.Height);
				Graphics graphics = Graphics.FromImage(image);
				this.ChartGraph.Graphics = graphics;
				this.Paint(this.ChartGraph.Graphics, false);
				image.Dispose();
				this.isSelectionMode = false;
				HotRegionsList list2 = base.Common.HotRegionsList;
				list2.ProcessChartMode |= ProcessMode.HotRegions;
			}
		}

		public void Recalculate()
		{
			foreach (ChartArea area in this._chartAreas)
			{
				if (area.Visible)
				{
					area.ReCalcInternal();
				}
			}
		}

		internal void ResetMinMaxFromData()
		{
			if (this._chartAreas != null)
			{
				foreach (ChartArea area in this._chartAreas)
				{
					if (area.Visible)
					{
						area.ResetMinMaxFromData();
					}
				}
			}
		}

		public void Resize(ChartGraphics chartGraph)
		{
			this.Resize(chartGraph, false);
		}

		public void Resize(ChartGraphics chartGraph, bool calcAreaPositionOnly)
		{
			base.Common.Width = this._width;
			base.Common.Height = this._height;
			chartGraph.SetPictureSize(this._width, this._height);
			RectangleF rectangle = new RectangleF(0f, 0f, (float)(this._width - 1), (float)(this._height - 1));
			rectangle = chartGraph.GetRelativeRectangle(rectangle);
			this._titlePosition = RectangleF.Empty;
			IBorderType borderType = null;
			bool flag = false;
			if (this._borderSkin.SkinStyle != BorderSkinStyle.None)
			{
				this._chartBorderPosition = chartGraph.GetAbsoluteRectangle(rectangle);
				borderType = base.Common.BorderTypeRegistry.GetBorderType(this._borderSkin.SkinStyle.ToString());
				if (borderType != null)
				{
					borderType.Resolution = chartGraph.Graphics.DpiX;
					flag = borderType.GetTitlePositionInBorder() != RectangleF.Empty;
					this._titlePosition = chartGraph.GetRelativeRectangle(borderType.GetTitlePositionInBorder());
					this._titlePosition.Width = rectangle.Width - this._titlePosition.Width;
					borderType.AdjustAreasPosition(chartGraph, ref rectangle);
				}
			}
			RectangleF empty = RectangleF.Empty;
			if (flag)
			{
				empty = new RectangleF(this._titlePosition.Location, this._titlePosition.Size);
			}
			foreach (Title title in this.Titles)
			{
				if (((title.DockedToChartArea == "NotSet") && title.Position.Auto) && title.Visible)
				{
					title.CalcTitlePosition(chartGraph, ref rectangle, ref empty, 3f);
				}
			}
			this.Legends.CalcLegendPosition(chartGraph, ref rectangle, 3f);
			rectangle.Width -= 3f;
			rectangle.Height -= 3f;
			RectangleF chartAreasRectangle = new RectangleF();
			int num = 0;
			foreach (ChartArea area in this._chartAreas)
			{
				if (area.Visible && area.Position.Auto)
				{
					num++;
				}
			}
			int num2 = (int)Math.Floor(Math.Sqrt((double)num));
			if (num2 < 1)
			{
				num2 = 1;
			}
			int num3 = (int)Math.Ceiling((double)(((float)num) / ((float)num2)));
			int num4 = 0;
			int num5 = 0;
			foreach (ChartArea area2 in this._chartAreas)
			{
				if (area2.Visible)
				{
					if (area2.Position.Auto)
					{
						chartAreasRectangle.Width = (rectangle.Width / ((float)num2)) - 3f;
						chartAreasRectangle.Height = (rectangle.Height / ((float)num3)) - 3f;
						chartAreasRectangle.X = (rectangle.X + (num4 * (rectangle.Width / ((float)num2)))) + 3f;
						chartAreasRectangle.Y = (rectangle.Y + (num5 * (rectangle.Height / ((float)num3)))) + 3f;
						TitleCollection.CalcOutsideTitlePosition(this, chartGraph, area2, ref chartAreasRectangle, 3f);
						this.Legends.CalcOutsideLegendPosition(chartGraph, area2, ref chartAreasRectangle, 3f);
						area2.Position.SetPositionNoAuto(chartAreasRectangle.X, chartAreasRectangle.Y, chartAreasRectangle.Width, chartAreasRectangle.Height);
						num5++;
						if (num5 >= num3)
						{
							num5 = 0;
							num4++;
						}
					}
					else
					{
						RectangleF ef4 = area2.Position.ToRectangleF();
						TitleCollection.CalcOutsideTitlePosition(this, chartGraph, area2, ref ef4, 3f);
						this.Legends.CalcOutsideLegendPosition(chartGraph, area2, ref ef4, 3f);
					}
				}
			}
			this.AlignChartAreasPosition();
			if (!calcAreaPositionOnly)
			{
				foreach (ChartArea area3 in this._chartAreas)
				{
					if (area3.Visible)
					{
						area3.Resize(chartGraph);
					}
				}
				this.AlignChartAreas(AreaAlignmentStyles.PlotPosition);
				TitleCollection.CalcInsideTitlePosition(this, chartGraph, 3f);
				this.Legends.CalcInsideLegendPosition(chartGraph, 3f);
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		object IServiceProvider.GetService(System.Type serviceType)
		{
			if (serviceType != typeof(ChartPicture))
			{
				throw new ArgumentException(SR.ExceptionChartPictureUnsupportedType(serviceType.ToString()));
			}
			return this;
		}

		internal void WriteChartMapTag(HtmlTextWriter output, string mapName)
		{
			output.WriteLine();
			output.AddAttribute(HtmlTextWriterAttribute.Name, mapName);
			output.AddAttribute(HtmlTextWriterAttribute.Id, mapName);
			output.RenderBeginTag(HtmlTextWriterTag.Map);
			MapAreasCollection areaItems = new MapAreasCollection();
			for (int i = 0; i < this._mapAreas.Count; i++)
			{
				if (!this._mapAreas[i].IsCustom)
				{
					areaItems.Add(this._mapAreas[i]);
					this._mapAreas.RemoveAt(i);
					i--;
				}
			}
			base.Common.Chart.CallOnCustomizeMapAreas(areaItems);
			foreach (MapArea area in areaItems)
			{
				area.IsCustom = false;
				this._mapAreas.Add(area);
			}
			foreach (MapArea area2 in this._mapAreas)
			{
				area2.RenderTag(output, base.Common.Chart);
			}
			if (this._mapAreas.Count == 0)
			{
				output.Write("<area shape=\"rect\" coords=\"0,0,0,0\" alt=\"\" />");
			}
			output.RenderEndTag();
		}

		[PersistenceMode(PersistenceMode.InnerProperty)]
		[Editor(typeof(AnnotationCollectionEditor), typeof(UITypeEditor))]
		[SRCategory("CategoryAttributeChart")]
		[SRDescription("DescriptionAttributeAnnotations3")]
		public AnnotationCollection Annotations
		{
			get
			{
				return this._annotations;
			}
		}

		[SRDescription("DescriptionAttributeAntiAlias")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Bindable(true)]
		[DefaultValue(typeof(AntiAliasingStyles), "All")]
		[SRCategory("CategoryAttributeImage")]
		public AntiAliasingStyles AntiAliasing
		{
			get
			{
				return this._antiAliasing;
			}
			set
			{
				this._antiAliasing = value;
			}
		}

		[Bindable(true)]
		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor))]
		[PersistenceMode(PersistenceMode.Attribute)]
		[TypeConverter(typeof(ColorConverter))]
		[SRCategory("CategoryAttributeAppearance")]
		[DefaultValue(typeof(Color), "White")]
		[SRDescription("DescriptionAttributeBackColor")]
		public Color BackColor
		{
			get
			{
				return this._backColor;
			}
			set
			{
				if (!(value == Color.Empty) && (value.A == 0xff))
				{
					bool flag1 = value == Color.Transparent;
				}
				this._backColor = value;
			}
		}

		[SRDescription("DescriptionAttributeBackGradientStyle")]
		[Editor(typeof(GradientEditor), typeof(UITypeEditor))]
		[Bindable(true)]
		[DefaultValue(0)]
		[SRCategory("CategoryAttributeAppearance")]
		[PersistenceMode(PersistenceMode.Attribute)]
		public GradientStyle BackGradientStyle
		{
			get
			{
				return this._backGradientStyle;
			}
			set
			{
				this._backGradientStyle = value;
			}
		}

		[Bindable(true)]
		[DefaultValue(0)]
		[SRDescription("DescriptionAttributeBackHatchStyle")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Editor(typeof(HatchStyleEditor), typeof(UITypeEditor))]
		[SRCategory("CategoryAttributeAppearance")]
		public ChartHatchStyle BackHatchStyle
		{
			get
			{
				return this._backHatchStyle;
			}
			set
			{
				this._backHatchStyle = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance")]
		[SRDescription("DescriptionAttributeBackImage")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[NotifyParentProperty(true)]
		[Editor(typeof(ImageValueEditor), typeof(UITypeEditor))]
		[Bindable(true)]
		[DefaultValue("")]
		public string BackImage
		{
			get
			{
				return this._backImage;
			}
			set
			{
				this._backImage = value;
			}
		}

		[PersistenceMode(PersistenceMode.Attribute)]
		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true)]
		[DefaultValue(0)]
		[NotifyParentProperty(true)]
		[SRDescription("DescriptionAttributeBackImageAlign")]
		public ChartImageAlignmentStyle BackImageAlignment
		{
			get
			{
				return this._backImageAlign;
			}
			set
			{
				this._backImageAlign = value;
			}
		}

		[Bindable(true), SRCategory("CategoryAttributeAppearance")]
		[DefaultValue(typeof(Color), "")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[NotifyParentProperty(true)]
		[SRDescription("DescriptionAttributeImageTransparentColor")]
		[TypeConverter(typeof(ColorConverter))]
		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor))]
		public Color BackImageTransparentColor
		{
			get
			{
				return this._backImageTransparentColor;
			}
			set
			{
				this._backImageTransparentColor = value;
			}
		}

		[DefaultValue(0)]
		[SRDescription("DescriptionAttributeImageWrapMode")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Bindable(true)]
		[SRCategory("CategoryAttributeAppearance")]
		[NotifyParentProperty(true)]
		public ChartImageWrapMode BackImageWrapMode
		{
			get
			{
				return this._backImageWrapMode;
			}
			set
			{
				this._backImageWrapMode = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Bindable(true)]
		[DefaultValue(typeof(Color), "")]
		[SRDescription("DescriptionAttributeBackSecondaryColor")]
		[TypeConverter(typeof(ColorConverter))]
		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor))]
		public Color BackSecondaryColor
		{
			get
			{
				return this._backSecondaryColor;
			}
			set
			{
				if ((value != Color.Empty) && ((value.A != 0xff) || (value == Color.Transparent)))
				{
					throw new ArgumentException(SR.ExceptionBackSecondaryColorIsTransparent);
				}
				this._backSecondaryColor = value;
			}
		}

		[PersistenceMode(PersistenceMode.Attribute)]
		[DefaultValue(typeof(Color), "White")]
		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeBorderColor")]
		[TypeConverter(typeof(ColorConverter))]
		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor))]
		public Color BorderColor
		{
			get
			{
				return this._borderColor;
			}
			set
			{
				this._borderColor = value;
			}
		}

		[SRDescription("DescriptionAttributeBorderDashStyle")]
		[Bindable(true)]
		[DefaultValue(0)]
		[SRCategory("CategoryAttributeAppearance")]
		[PersistenceMode(PersistenceMode.Attribute)]
		public ChartDashStyle BorderDashStyle
		{
			get
			{
				return this._borderDashStyle;
			}
			set
			{
				this._borderDashStyle = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true)]
		[DefaultValue(0)]
		[SRDescription("DescriptionAttributeBorderSkin")]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		public BorderSkin BorderSkin
		{
			get
			{
				return this._borderSkin;
			}
			set
			{
				this._borderSkin = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true)]
		[DefaultValue(1)]
		[SRDescription("DescriptionAttributeChart_BorderlineWidth")]
		[PersistenceMode(PersistenceMode.Attribute)]
		public int BorderWidth
		{
			get
			{
				return this._borderWidth;
			}
			set
			{
				if (value < 0)
				{
					throw new ArgumentOutOfRangeException("value", SR.ExceptionChartBorderIsNegative);
				}
				this._borderWidth = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance")]
		[Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor))]
		[SRDescription("DescriptionAttributeChartAreas")]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[Bindable(true)]
		public ChartAreaCollection ChartAreas
		{
			get
			{
				return this._chartAreas;
			}
		}

		internal ChartGraphics ChartGraph { set; get; }

		[SerializationVisibility(SerializationVisibility.Hidden)]
		[SRCategory("CategoryAttributeData")]
		[SRDescription("DescriptionAttributeDataManipulator")]
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public DataManipulator DataManipulator
		{
			get
			{
				return this._dataManipulator;
			}
		}

		internal FontCache FontCache
		{
			get
			{
				return this._fontCache;
			}
		}

		[PersistenceMode(PersistenceMode.Attribute)]
		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true), DefaultValue(300)]
		[SRDescription("DescriptionAttributeHeight3")]
		public int Height
		{
			get
			{
				return this._height;
			}
			set
			{
				this.InspectChartDimensions(this.Width, value);
				this._height = value;
				base.Common.Height = value;
			}
		}

		[Bindable(true)]
		[DefaultValue(true)]
		[SRCategory("CategoryAttributeMap")]
		[SRDescription("DescriptionAttributeMapEnabled")]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		public bool IsMapEnabled
		{
			get
			{
				return this._isMapEnabled;
			}
			set
			{
				this._isMapEnabled = value;
			}
		}

		[PersistenceMode(PersistenceMode.Attribute)]
		[SRCategory("CategoryAttributeImage")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSoftShadows3")]
		[DefaultValue(true)]
		public bool IsSoftShadows
		{
			get
			{
				return this._isSoftShadows;
			}
			set
			{
				this._isSoftShadows = value;
			}
		}

		[PersistenceMode(PersistenceMode.InnerProperty)]
		[SRDescription("DescriptionAttributeLegends")]
		[Editor(typeof(LegendCollectionEditor), typeof(UITypeEditor))]
		[SRCategory("CategoryAttributeChart")]
		public LegendCollection Legends
		{
			get
			{
				return this._legends;
			}
		}

		[Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor))]
		[SRDescription("DescriptionAttributeMapAreas")]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[SRCategory("CategoryAttributeMap")]
		public MapAreasCollection MapAreas
		{
			get
			{
				return this._mapAreas;
			}
		}

		[DefaultValue(0)]
		public System.Windows.Forms.RightToLeft RightToLeft
		{
			get
			{
				return this.rightToLeft;
			}
			set
			{
				this.rightToLeft = value;
			}
		}

		[SRCategory("CategoryAttributeMisc")]
		[SRDescription("DescriptionAttributeSuppressExceptions")]
		[DefaultValue(false)]
		internal bool SuppressExceptions
		{
			get
			{
				return this._suppressExceptions;
			}
			set
			{
				this._suppressExceptions = value;
			}
		}

		[SRCategory("CategoryAttributeImage")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Bindable(true)]
		[DefaultValue(typeof(TextAntiAliasingQuality), "High")]
		[SRDescription("DescriptionAttributeTextAntiAliasingQuality")]
		public TextAntiAliasingQuality TextAntiAliasingQuality
		{
			get
			{
				return this._textAntiAliasingQuality;
			}
			set
			{
				this._textAntiAliasingQuality = value;
			}
		}

		[SRDescription("DescriptionAttributeTitles")]
		[Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor))]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[SRCategory("CategoryAttributeCharttitle")]
		public TitleCollection Titles
		{
			get
			{
				return this._titles;
			}
		}

		[PersistenceMode(PersistenceMode.Attribute)]
		[DefaultValue(300)]
		[SRDescription("DescriptionAttributeWidth")]
		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true)]
		public int Width
		{
			get
			{
				return this._width;
			}
			set
			{
				this.InspectChartDimensions(value, this.Height);
				this._width = value;
				base.Common.Width = this._width;
			}
		}
	}
}

